﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.IdentityModel.Claims;

namespace Veracruz.IdentityModel
{
    public static class ClaimsIdentityExtensionMethods
    {
        public static Claim GetClaim(this IClaimsIdentity claimsIdentity, string claimType)
        {
            if (claimsIdentity == null)
            {
                throw new ArgumentNullException("claimsIdentity");
            }
            for (int i = 0; i < claimsIdentity.Claims.Count; i++)
            {
                if (claimsIdentity.Claims[i].ClaimType == claimType)
                {
                    return claimsIdentity.Claims[i];
                }
            }
            return null;
        }
        public static string GetClaimValue(this IClaimsIdentity claimsIdentity, string claimType)
        {
            Claim l_claim = claimsIdentity.GetClaim(claimType);
            return (l_claim == null ? null : l_claim.Value); // TODO : Take into account ValueType property to return a strong typed value.
        }
    }
}
